Golang : Split string
Problem :
Need to split this string ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES by comma
Solution :
Use the strings.Split function to split the string
package main
import (
"fmt"
"strings"
)
func main() {
str := "ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES"
strarray := strings.Split(str, ",")
fmt.Println(strarray)
}
Output :
[ADAM EVE CALEB SCOTT GRANTT JAMES]
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.4k Golang : Check if password length meet the requirement
+21.2k Golang : GORM create record or insert new record into database example
+15k Golang : Find location by IP address and display with Google Map
+5.1k Golang : Return multiple values from function
+5.7k Golang : Function as an argument type example
+16.1k CodeIgniter/PHP : Create directory if does not exist example
+31.7k Golang : Validate email address with regular expression
+20.4k Golang : Convert date string to variants of time.Time type examples
+27.3k PHP : Count number of JSON items/objects
+6.4k Golang : Experimental emojis or emoticons icons programming language
+15.4k Golang : How to login and logout with JWT example